package com.itheima.test;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Server {
    public static void main(String[] args) throws IOException {
        // 1 创建服务端的Socket对象
        ServerSocket serverSocket = new ServerSocket(10086);
        // 自定义线程池
        ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(20, 20, 0, TimeUnit.HOURS, new ArrayBlockingQueue<>(40), Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());

        while (true) {
            // 2 监听客户端的链接
            Socket socket = serverSocket.accept();
            // new Thread(new ServerThread(socket)).start();
            poolExecutor.submit(new ServerThread(socket));
        }
    }
}
